//
//  Camera.m
//  SSE


#import "Camera.h"


@implementation Camera

- (id)initCameraWithView
{
	[super init];
	eye.x = 0;
	eye.y = 0;
	eye.z = 40.0;
	look.x = 15;
	look.y = 15;
	look.z = 0;
	[self setNormalNorth];
	[self setZoom: 60.0];
	[self setPitch: 0.0];
	[self setRoll: 0.0];
	[self setYaw: 0.0];
	return self;
}

- (void)updateCamera
{
	if(zoom < 1.0) zoom = 1.0;
	if(yaw > TWOPI) yaw -= TWOPI;
	else if(yaw <- 0) yaw += TWOPI;
	
		eye.x = look.x + zoom*sin(yaw)*sin(pitch);
		eye.y = look.y - zoom*cos(yaw)*sin(pitch);
		eye.z = zoom*cos(pitch);
		
		look.z = 0.0;
	
	gluLookAt(eye.x,eye.y,eye.z,look.x,look.y,look.z,norm.a,norm.b,norm.c);
}

- (void)Zoom:(float)zum
{
	zoom += zum;
}

- (void)setZoom:(float)zum
{
	zoom = zum;
}

- (float)getZoom
{
	return zoom;
}

- (void)setPitch:(float)pich
{
	pitch = pich;
}

- (void)Pitch:(float)pich
{
	pitch += pich;
}

- (void)setRoll:(float)rol
{
	roll += rol;
}

- (void)setYaw:(float)ya
{
	yaw += ya;
}

- (void)lookX:(float)x Y:(float)y Z:(float)z
{
	look.x += x;
	look.y += y;
	look.z += z;
}

- (void)eyeX:(float)x Y:(float)y Z:(float)z
{
	eye.x += x;
	eye.y += y;
	eye.z += z;
}

- (void)setLookX:(float)x Y:(float)y Z:(float)z
{
	look.x = x;
	look.y = y;
	look.z = z;
}

- (void)setLook:(Point3f *)position
{
	look = *position;
}

- (void)setNormal:(Vector3f)vect
{
	norm = vect;
}

- (void)setNormalNorth
{
	norm.a = 0;
	norm.b = 1;
	norm.c = 0;
}
	
@end
